<script setup >
import { defineProps, ref } from 'vue'
import { getGoodsHotAPI } from '@/api'

const props = defineProps({
  type: {
    type: Number,
    default: 1
  },
  goodsId: {
    type: String,
    default: ''
  }
})
console.log(props.goodsId)

// 标题对象
const titleObj = {
  1: '24小时热销榜',
  2: '周热销榜',
  3: '总热销榜'
}

const hotList = ref([])
const getGoodsHotFn = async() => {
  const res = await getGoodsHotAPI(props.goodsId, props.type)
  console.log(res)
  hotList.value = res.result
}
getGoodsHotFn()
</script>

<template>
  <div class="goods-hot">
    <h3>{{ titleObj[props.type] }}</h3>
    <div class="goods-list">
      <!-- 商品区块 -->
      <goodsItem v-for="(item, index) in hotList" :key="index" :goods="item"/>
    </div>
  </div>
</template>

<style scoped lang="less">
.goods-hot {
  background-color: #fff;
  margin-bottom: 20px;
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-list {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}
</style>
